'use strict';
var Schema = require('mongoose').Schema,
    Model = require('../../../Base/server/controllers/Model');

var modelField = {};
//条码主档
modelField.BarcodeMaster = {
    type: Schema.ObjectId,
    ref: 'BarcodeMaster'
};
//采集时间
modelField.CollectDateTime = {
    type: Date,
    default: Date.now
};
//终端
modelField.Terminal = {
    type: Schema.ObjectId,
    ref: 'Terminal'
};
//终端名称
modelField.TerminalName = {
    type: String,
    trim: true
};
//工序
modelField.Operation = {
    type: Schema.ObjectId,
    ref: 'Operation'
};
//工序名称
modelField.OperationName = {
    type: String,
    trim: true
};
//作业
modelField.Work = {
    type: Schema.ObjectId,
    ref: 'Work'
};
//作业名称
modelField.WorkName = {
    type: String,
    trim: true
};
//工位
modelField.WorkLocation = {
    type: Schema.ObjectId,
    ref: 'WorkLocation'
};
//工位名称
modelField.WorkLocationName = {
    type: String,
    trim: true
};
//用户集合
modelField.Users = {
    type: [
        {
            type: Schema.ObjectId,
            ref: 'User'
        }
    ]
};
//业务状态 0: 开始 1: 完成
modelField.BusinessStatus = {
    type: Number
};
//质检类型 0: 全检 1:巡检 2:首件质检
modelField.QCType = {
    type: Number
};
//质检状态 0: 合格 1:不合格 2:让步接收 3:品质判定 4:返工 5:报废
modelField.QCStatus = {
    type: Number
};
//质检人，首件质检用
modelField.QCUser = {
    type: Schema.ObjectId,
    ref: 'User'
};
//质检时间，首件质检用
modelField.QCDateTime = {
    type: Date
};
//备注
modelField.Remark = {
    type: String,
    trim: true
};

var newModel = new Model(modelField);
newModel.addIndex({BarcodeMaster: 1});
newModel.addIndex({WorkLocation: 1});
newModel.addIndex({BarcodeMaster: 1, CollectDateTime: 1}, {"unique": true});
newModel.create('BizRecord', '条码流水');
